document.oncontextmenu = function() { return true; }

var dialog = document.getElementById('dialog');
if (dialog == null) {
	var dialog = document.createElement('dialog');
	dialog.setAttribute('id', 'dialog');
	dialog.setAttribute('open', 'open');
	dialog.style.position = 'fixed';
	dialog.style.margin = '0px';
	dialog.style.top = '100px';
	dialog.style.left = '0px';
	dialog.style.zIndex = 10000;
	document.body.appendChild(dialog);
}
dialog.innerHTML = '';
dialog.style.display = 'block';
var button = document.createElement('button');
button.textContent=' X ';
dialog.appendChild(button);
button.onclick = function(){
    dialog.style.display = 'none';
}
var br = document.createElement('br');
dialog.appendChild(br);

var sources = document.getElementsByTagName('source');
var videos = document.getElementsByTagName('video');
var embeds = document.getElementsByTagName('embed');
var iframes = document.getElementsByTagName('iframe');
var url = '';

if(iframes.length != 0){
	for(i=0; i<iframes.length; i++){
		if(iframes[i].src.indexOf('pos.baidu.com') == -1){
			var a = document.createElement('a');
			a.textContent = 'iframe' + i;
			a.href = unescape(iframes[i].src);
			a.target = '_blank';
            a.style = 'color:black;';
			dialog.appendChild(a);
			var br = document.createElement('br');
			dialog.appendChild(br);
		}
		if(iframes[i].src.indexOf('https://baiduyunbo.com/?id=') == 0){
			var id = iframes[i].src.replace('https://baiduyunbo.com/?id=','');
			var a = document.createElement('a');
			a.textContent = id;
			a.href = 'https://m3u8.cdnpan.com/'+ id + '.m3u8';
			dialog.appendChild(a);
			var br = document.createElement('br');
			dialog.appendChild(br);
		}
	}
}

for (i=0; i<videos.length; i++) {
	if (videos[i].hasAttribute("controlslist")) {
		videos[i].removeAttribute("controlslist");
	}
    var a = document.createElement('a');
    a.textContent = 'video';
    a.href = videos[i].src;
    a.target = '_blank';
    dialog.appendChild(a);
    var br = document.createElement('br');
    dialog.appendChild(br);
}

if(sources.length != 0){
	url = sources[0].src;
}else if(videos.length != 0){
	if(videos[0].classList.contains('dplayer-video')){
		var div = document.getElementsByClassName('dplayer-info-panel-item-url');
		console.log(div);
		url = div[0].textContent.replace('Video url','');
	}else{
		url = videos[0].src;
	}
}else if(embeds.length != 0){
	url = embeds[0].src;
	if(url.indexOf('.swf') != -1) {        
        var flashvars = embeds[0].getAttribute("flashvars");
		console.log(flashvars);
		if(flashvars == null){
			url = url.substr(url.indexOf('=')+1);
		}else{
			var flashvars = flashvars.split('&');
				for(var i=0; i<flashvars.length; i++){            
					if(flashvars[i].indexOf('video=')==0){
						url = flashvars[i].substring(6);						
					}
				}
		}
    }
}else{	
	if(iframes.length != 0){
		//console.log(iframes[0].src);
		videos = iframes[0].contentWindow.document.getElementsByTagName('video');
		if(videos.length != 0){
			url = videos[0].src;
		}
		iframes[0].contentWindow.document.oncontextmenu = function() { return true; }
	}
}

	
if(url != ''){
    //var domain = location.host;
    //console.info(domain);
	url = url.replace(/%3A/g,':').replace(/%2F/g,'/');	//无效
	//alert(url);
    var a = document.createElement('a');
    a.textContent = 'video';
    a.href = url;
    a.target = '_blank';
    dialog.appendChild(a);
    var br = document.createElement('br');
    dialog.appendChild(br);
}